import request from '@/utils/request'
import store from '@/store'
//const ascriptionId = store.state.userInfo.ascriptionId;

// 页面内容 左侧树
export function getPage(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize
  }
  return request({
    url: '/getStaffPage',
    method: 'post',
    data: data
  })
}

// 数据列表  workType 工种id 多个逗号隔开
export function listData(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    deptId: queryParams.deptId,
    workType: queryParams.workType,
    post: queryParams.postId,
    keywords: queryParams.keywords
  }
  return request({
    url: '/getStaffList',
    method: 'post',
    data: data
  })
}


//  新增
export function addData(val) {
  const data = {
    projectContent: {
      ascriptionId: store.state.userInfo.ascriptionId, //机构 id
      jobNumber: val.jobNumber, //工号
      fullName: val.fullName, //姓名
      password: val.password, //登录密码
      genderId: val.genderId, //性别 id 1-男 2-女
      genderVal: val.genderVal, //性别的文字值
      deptId: val.deptId, //所属部门 id
      deptVal: val.deptVal, //所属部门的文字值
      phone: val.phone, //手机号
      idCard: val.idCard, //身份证号
      workIds: val.workIds, //工种 id  多个格式为：‘165,166,167’
      workVal: val.workVal, //工种的文字值  多个格式为：‘电工,电焊工,瓦工’
      postId: val.postId, //岗位 id
      postVal: val.postVal, //岗位的文字值
      job: val.job, //职务 id
      jobVal: val.jobVal, //职务的文字值
      nationVal: val.nationVal, //民族 id
      nation: val.nation, //民族
      email: val.email, //邮箱
      entryTime: val.entryTime, //入职时间
      address: val.address, //家庭住址
      avatar: val.avatar, //个人照片
      wechat: val.wechat, //微信号
      headPortrait: val.headPortrait, //头像照片
      employeeType: val.employeeType, //员工类型 id
      employeeTypeVal: val.employeeTypeVal, //员工类型的文字值
      enable: val.enable, //启用状态 0-未启用 1-已启用
      idCardImg: val.idCardImg, //身份证图片
      idCardImg1: val.idCardImg1, //身份证图片 正面
      idCardImg2: val.idCardImg2 //身份证图片 反面
    }
  }
  data.projectContent.ascriptionId = store.state.userInfo.ascriptionId
  return request({
    url: '/addStaff',
    method: 'post',
    data: data
  })
}

// 获取单条数据
export function getData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/getStaffData',
    method: 'post',
    data: data
  })
}

// 修改
export function updateData(val) {
  const data = {
    projectContent: {
      ascriptionId: store.state.userInfo.ascriptionId, //机构 id
      theid: val.theid, //id
      jobNumber: val.jobNumber, //工号
      fullName: val.fullName, //姓名
      password: val.password, //登录密码
      genderId: val.genderId, //性别 id 1-男 2-女
      genderVal: val.genderVal, //性别的文字值
      deptId: val.deptId, //所属部门 id
      deptVal: val.deptVal, //所属部门的文字值
      phone: val.phone, //手机号
      idCard: val.idCard, //身份证号
      workIds: val.workIds, //工种 id  多个格式为：‘165,166,167’
      workVal: val.workVal, //工种的文字值  多个格式为：‘电工,电焊工,瓦工’
      postId: val.postId, //岗位 id
      postVal: val.postVal, //岗位的文字值
      job: val.job, //职务 id
      jobVal: val.jobVal, //职务的文字值
      nationVal: val.nationVal, //民族 id
      nation: val.nation, //民族
      email: val.email, //邮箱
      entryTime: val.entryTime, //入职时间
      address: val.address, //家庭住址
      avatar: val.avatar, //个人照片
      wechat: val.wechat, //微信号
      headPortrait: val.headPortrait, //头像照片
      employeeType: val.employeeType, //员工类型 id
      employeeTypeVal: val.employeeTypeVal, //员工类型的文字值
      enable: val.enable, //启用状态 0-未启用 1-已启用
      idCardImg: val.idCardImg, //身份证图片
      idCardImg1: val.idCardImg1, //身份证图片 正面
      idCardImg2: val.idCardImg2 //身份证图片 反面
    }
  }
  return request({
    url: '/updateStaff',
    method: 'post',
    data: data
  })
}

// 批量修改工种  
export function changeWorkType(val) {
  const data = {
    projectContent: {
      theid: val.theid, //id 修改多个格式为：‘165,166,167’
      workIds: val.workIds, //工种 id  多个格式为：‘165,166,167’
      workVal: val.workVal, //工种的文字值  多个格式为：‘电工,电焊工,瓦工’
    }
  }
  // theid
  return request({
    url: '/changeWorkTypeStaff',
    method: 'post',
    data: data
  })
}

// 批量修改岗位 
export function changePost(val) {
  const data = {
    projectContent: {
      theid: val.theid, //id  修改多个格式为：‘165,166,167’
      postId: val.postId, //岗位 id
      postVal: val.postVal, //岗位的文字值
    }
  }
  // theid
  return request({
    url: '/changePostStaff',
    method: 'post',
    data: data
  })
}

// 删除
export function delData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/delStaff',
    method: 'post',
    data: data
  })
}

// 批量删除   idListStr id列表  逗号隔开
export function delMultiData(idListStr) {
  const data = {
    idListStr
  }
  return request({
    url: '/delMultipleStaff',
    method: 'post',
    data: data
  })
}

// 下拉框 工种、岗位
export function getStaffCom() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getStaffComboBox',
    method: 'post',
    data: data
  })
}

// 下拉框 证书
export function getCertificate() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getCertificateComboBox',
    method: 'post',
    data: data
  })
}

// 状态启用
export function EnableStaff(theid, enable) {
  const data = {
    projectContent: {
      theid,
      enable
    }
  }
  return request({
    url: '/changeEnableStaff',
    method: 'post',
    data: data
  })
}